package com.wanxi.login;

import com.wanxi.MyScanner;

public class Login {
    /**
     * 1.提示用户输入用户名和密码
     * 2.创建一个原有的用户名和密码
     * 3.进行比较，得出不同的登录逻辑
     */
    public static void main(String[] args) {
        String user = "admin";
        String pass = "123456";

//        for (int i = 0; i < 3; i++) {
//            MyScanner myScanner = new MyScanner();
//            String username = myScanner.getString("请输入用户名");
//            String password = myScanner.getString("请输入密码");
//            if (judge(user, pass, username, password)) {
//                return;
//            }
//        }
//        System.out.println("你的三次机会已经用完，登录失败");
//        死循环
        int time = 0;
        MyScanner myScanner = new MyScanner();
        while (true) {
            String username = myScanner.getString("请输入用户名");
            String password = myScanner.getString("请输入密码");
            if (judge(user, pass, username, password)) {
                return;
            }
            time++;
            if (time >= 3) {
                System.out.println("你的三次机会已经用完，登录失败");
                return;
            }

        }
    }

    private static boolean judge(String user, String pass, String username, String password) {
        if (user.equals(username) & pass.equals(password)) {
            System.out.println("登录成功");
            return true;
        } else {
            System.out.println("用户名或者密码错误");
            return false;
        }
    }
}
